<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="format-detection" content="telephone=no">
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
	<title>个人认证</title>

	<link href="<?php echo TEMPLATE_SITE_URL;?>/css/common.css" type="text/css" rel="stylesheet">
	<link href="<?php echo TEMPLATE_SITE_URL;?>/css/my.renzheng.step.css" type="text/css" rel="stylesheet">
</head>
<body>
<!--  
    <div class="menuList individual">
                <div class="menuItem selected">
            <a href="/myVerify/verifyInfo/operator/individual">个人信息</a>        </div>
        <div class="menuItem arrow"></div>
        <div class="menuItem">
            店铺信息        </div>
        <div class="menuItem arrow"></div>
        <div class="menuItem">
            提交审核        </div>
    </div>
-->
<style type="text/css">
    .verifyMain .verifyBox.operator {
        background-color: #FFF;
    }
</style>
<div id="contentbox">
    <div class="verifyMain operator individual">
        <div class="verifyBox operator">
            <div class="title">
                实名认证
                <span>(请上传真实的个人信息，认证通过后将无法修改)</span>
            </div>
            <div class="infoItem text">
                <div class="liHead">姓名</div>
                <div class="liContent">
                    <input type="text" class="input" name="name" placeholder="请输入真实的姓名" value="">
                </div>
                <div class="liFoot"></div>
            </div>
            <div class="infoItem text">
                <div class="liHead">身份证号</div>
                <div class="liContent">
                    <input type="text" class="input" name="idCode" placeholder="请输入身份证号" maxlength="18" value="">
                </div>
                <div class="liFoot"></div>
            </div>
            <div class="infoItem text last">
                <div class="liHead">联系电话</div>
                <div class="liContent">
                    <input type="text" class="input" name="tel" placeholder="请输入联系电话" maxlength="11" value="">
                </div>
                <div class="liFoot"></div>
            </div>
            <div class="tips">请填写有效电话，工作人员将会致电核实材料</div>
        </div>

        <div class="verifyBox operatorPhoto">
            <div class="infoItem photo">
                <div class="liHead">
                    身份证正面照
                    <p class="">请用手机横向拍摄以保证图片正常显示</p>
                </div>
                <div class="liContent" serverid="" style="background-image: url(none)">
                                        <div class="example">
                        <div class="examplePhoto">
                            <img src="<?php echo TEMPLATE_SITE_URL;?>/images/verifyIdCodeFront.jpg" class="idcard1img">
                        </div>
                        <input type="hidden" name="idcard1img">
                        <div class="button idcard1">上传正面照</div>
                        <p>照片必须清晰哟！</p>
                    </div>
                                    </div>
            </div>
            <div class="infoItem photo">
                <div class="liHead">
                    身份证反面照
                    <p class="">请用手机横向拍摄以保证图片正常显示</p>
                </div>
                <div class="liContent" serverid="" style="background-image: url(none)">
                                        <div class="example">
                        <div class="examplePhoto">
                            <img src="<?php echo TEMPLATE_SITE_URL;?>/images/verifyIdCodeBack.jpg" class="idcard2img">
                        </div>
                        <input type="hidden" name="idcard2img">
                        <div class="button idcard2">上传反面照</div>
                        <p>照片必须清晰哟！</p>
                    </div>
                                    </div>
            </div>
            <div class="infoItem photo last">
                <div class="liHead">
                    手持身份证照
                    <p class="">拍照时请对焦在证件上(屏幕上对着身份证按一下)</p>
                </div>
                <div class="liContent hold" serverid="" style="background-image: url(none)">
                                        <div class="example">
                        <div class="examplePhoto">
                            <img src="<?php echo TEMPLATE_SITE_URL;?>/images/verifyIdCodeHold.png" class="idcard3img">
                        </div>
                        <input type="hidden" name="idcard3img">
                        <div class="button idcard3">上传手持身份证照</div>
                        <p>请严格按照范例姿势拍照，否则不会通过审核！</p>
                    </div>
                                    </div>
            </div>
            <div class="tips confirm">
                <div>请确认以上信息准确无误</div>
            </div>
        </div>

        <div class="buttonBanner">
        	<p style="color:red;margin:5px 10px 10px 15px;" class="error"></p>
            <button class="next">下一步</button>
        </div>
        
        
    </div>
</div>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/zepto.js"></script>
<script>
wx.config({
    appId: '<?php echo $output['signPackage']["appId"];?>',
    timestamp: <?php echo $output['signPackage']["timestamp"];?>,
    nonceStr: '<?php echo $output['signPackage']["nonceStr"];?>',
    signature: '<?php echo $output['signPackage']["signature"];?>',
   jsApiList: [
               'checkJsApi',
               'onMenuShareTimeline',
               'onMenuShareAppMessage',
               'onMenuShareQQ',
               'onMenuShareWeibo',
               'hideMenuItems',
               'showMenuItems',
               'hideAllNonBaseMenuItem',
               'showAllNonBaseMenuItem',
               'translateVoice',
               'startRecord',
               'stopRecord',
               'onRecordEnd',
               'playVoice',
               'pauseVoice',
               'stopVoice',
               'uploadVoice',
               'downloadVoice',
               'chooseImage',
               'previewImage',
               'uploadImage',
               'downloadImage',
               'getNetworkType',
               'openLocation',
               'getLocation',
               'hideOptionMenu',
               'showOptionMenu',
               'closeWindow',
               'scanQRCode',
               'chooseWXPay',
               'openProductSpecificView',
               'addCard',
               'chooseCard',
               'openCard'
      ]
  });
wx.ready(function () {
// 	wx.hideOptionMenu();
	wx.showMenuItems({
	    menuList: ["menuItem:share:appMessage","menuItem:share:timeline","menuItem:favorite","menuItem:openWithSafari","menuItem:share:email","menuItem:copyUrl","menuItem:readMode"] // 要显示的菜单项，所有menu项见附录3
	});

	$('.idcard1').click(function(){
		wx.chooseImage({
			count: 1,
			success: function (res){
				var localIds = res.localIds; 
				wx.uploadImage({
				    localId: localIds[0], // 需要上传的图片的本地ID，由chooseImage接口获得
				    isShowProgressTips: 1, // 默认为1，显示进度提示
				    success: function (res) {
				        var serverId = res.serverId; // 返回图片的服务器端ID
						$.ajax({
							type:'post',
							url:'index.php?act=renzheng&op=uploadpic',
							data:{serverId:serverId},
							dataType:'json',
							success:function(data){			
								if(data.state){
									$('input[name=idcard1img]').val(data.filename);
									$('.idcard1img').attr('src','<?php echo UPLOAD_SITE_URL;?>/shop/zhizhao/'+data.filename);
								}								
								return false;										
							}
						});
				    }
				});
			}
		});
	});

	$('.idcard2').click(function(){
		wx.chooseImage({
			count: 1,
			success: function (res){
				var localIds = res.localIds; 
				wx.uploadImage({
				    localId: localIds[0], // 需要上传的图片的本地ID，由chooseImage接口获得
				    isShowProgressTips: 1, // 默认为1，显示进度提示
				    success: function (res) {
				        var serverId = res.serverId; // 返回图片的服务器端ID
						$.ajax({
							type:'post',
							url:'index.php?act=renzheng&op=uploadpic',
							data:{serverId:serverId},
							dataType:'json',
							success:function(data){			
								if(data.state){
									$('input[name=idcard2img]').val(data.filename);
									$('.idcard2img').attr('src','<?php echo UPLOAD_SITE_URL;?>/shop/zhizhao/'+data.filename);
								}								
								return false;										
							}
						});
				    }
				});
			}
		});
	});


	$('.idcard3').click(function(){
		wx.chooseImage({
			count: 1,
			success: function (res){
				var localIds = res.localIds; 
				wx.uploadImage({
				    localId: localIds[0], // 需要上传的图片的本地ID，由chooseImage接口获得
				    isShowProgressTips: 1, // 默认为1，显示进度提示
				    success: function (res) {
				        var serverId = res.serverId; // 返回图片的服务器端ID
						$.ajax({
							type:'post',
							url:'index.php?act=renzheng&op=uploadpic',
							data:{serverId:serverId},
							dataType:'json',
							success:function(data){			
								if(data.state){
									$('input[name=idcard3img]').val(data.filename);
									$('.idcard3img').attr('src','<?php echo UPLOAD_SITE_URL;?>/shop/zhizhao/'+data.filename);
								}								
								return false;										
							}
						});
				    }
				});
			}
		});
	});
});

</script>
<script type="text/javascript">
$(function(){

    //验证身份证
    function validateIDCard(idCode) {
        if(!idCode) return false;
        var reg = /^((11|12|13|14|15|21|22|23|31|32|33|34|35|36|37|41|42|43|44|45|46|50|51|52|53|54|61|62|63|64|65|71|81|82|91)\d{4})((((19|20)(([02468][048])|([13579][26]))0229))|((20[0-9][0-9])|(19[0-9][0-9]))((((0[1-9])|(1[0-2]))((0[1-9])|(1\d)|(2[0-8])))|((((0[1,3-9])|(1[0-2]))(29|30))|(((0[13578])|(1[02]))31))))((\d{3}(x|X))|(\d{4}))$/;
        if(reg.test(idCode) === false) {
            if(validateTWIDCard(idCode) === true) {
                return true;
            }
            return false;
        }
        return true;
    }

    //验证台湾身份证号
    function validateTWIDCard(idCode) {
        var reg = /^[a-zA-Z][0-9]{9}$/;
        if(reg.test(idCode) !== false){
            var twFirstCode = {"A":10, "B":11, "C":12, "D":13, "E":14, "F":15, "G":16, "H":17, "J":18, "K":19, "L":20, "M":21, "N":22, "P":23, "Q":24, "R":25, "S":26, "T":27, "U":28, "V":29, "X":30, "Y":31, "W":32, "Z":33, "I":34, "O":35};
            var start = idCode.substring(0, 1);
            var mid = idCode.substring(1, 9);
            var end = idCode.substring(9, 10) * 1;
            var iStart = twFirstCode[start];
            var sum = parseInt(iStart / 10 + (iStart % 10) * 9);
            var iflag = 8;
            for (var c in mid) {
                sum = sum + mid[c] * iflag;
                iflag--;
            }
            return (sum % 10 == 0 ? 0 : (10 - sum % 10)) == end ? true : false;
        }
        return false;
    }
    
    //验证是否手机号码
    function isMobile(text) {
        var _emp = /^\s*|\s*$/g;
        text = text.replace(_emp, "");
        var _d = /^1[3578][01379]\d{8}$/g;
        var _l = /^1[34578][01256]\d{8}$/g;
        var _y = /^(134[012345678]\d{7}|184\d{8}|1[34578][012356789]\d{8})$/g;
        if (_d.test(text)) {
            return 3;
        } else if (_l.test(text)) {
            return 2;
        } else if (_y.test(text)) {
            return 1;
        }
        return 0;
    }
    
	
	$('.next').click(function(){
		var name = $("input[name=name]").val();
		var idCode = $("input[name=idCode]").val();	
		var tel = $("input[name=tel]").val();
		var idcard1img = $('input[name=idcard1img]').val();
		var idcard2img = $('input[name=idcard2img]').val();
		var idcard3img = $('input[name=idcard3img]').val();

		var error = '';

		if(name == ''){
			error+='姓名不能为空，';
		}
		
		if(!validateIDCard(idCode)){
			error+='身份证号不正确，';
		}

		if(!isMobile(tel)){
			error+='手机号不正确，';
		}

		//if(idcard1img == ''){
		//	error+='身份证正面照不能为空，';
		//}

		//if(idcard2img == ''){
		//	error+='身份证反面照不能为空，';
		//}
		//if(idcard3img == ''){
		//	error+='手持身份证照不能为空，';
		//}
		
		if(error != ''){
			$('.error').html(error);			
			return false;			
		}

		$.ajax({
			type:'post',
			url:'index.php?act=renzheng&op=stepperson',
			data:{name:name,idCode:idCode,tel:tel,idcard1img:idcard1img,idcard2img:idcard2img,idcard3img:idcard3img},
			dataType:'json',
			success:function(data){
				if(data.state==1){
					location.href = 'index.php?act=renzheng&op=stepperson1';
				}
				return false;
			}
		});
		
	});
	
});

</script>
</body>
</html>